<?
include_once("codelibrary/inc/variables.php");//Using variables.php for Database Connectivity
include_once("codelibrary/inc/functions.php");//Using functions.php for using getAnyTableWhereData()

include_once("codelibrary/inc/mailer.class.php");

$Record=getAnyTableWhereData($administrator_info_table," and username='$TRLEN_UserName' ");

//if User exists  --redirecting to previous page					
if($Record)
{
	
	$hflds="";
			if (!empty($HTTP_POST_VARS)) 
			{
				reset($HTTP_POST_VARS);
				while (list($k,$v)=each($HTTP_POST_VARS)) 
				{
					   ${$k}=$v;
						$hflds .= "<input type=hidden name='".$k."' value='".$v."'>";
				}	
			}	
				$hflds .= "<input type=hidden name=err value='alreadyexists'>";
				echo "<form name=f1 action='free-trial.php' method=post>";
				echo $hflds."</form>";
				echo "<script>location.href='free-trial.php?err=alreadyexists'</script>";
				die();
}
else
{	
    ###############   Inserting Information Of Business Into business_info_table #############
    $businesscategory = traverse($array_business_category,$TR_BusinessCategory,1,'','');
	$companyname=$TR_Company;
	$locationname=$companyname;   // will be added from company =>Location Information
	$parent=0;         // 0 for Main HeadQuarters Location Of the company
	$firstname=$TRFN_FirstName;
	$lastname=$TRFN_LastName;
	$email=$TREF_Email;
	$address=$TR_Address;
	$city=$TR_City;
	$state=$TR_State; //Work To Do:- Converting Short Form Of States Into There Full forms e.g: AK - Alaska
	$zipcode=$TR_Zip;
	$country=$TR_Country;
	$timezone=$TR_TimeZone;
	$phonenumber=$PHR_Phone;
	$altphonenumber=$PHN_AltPhone;
	$faxnumber=$TN_Fax;
	$directions='';
	$webaddress=$TN_WebAddress;
	////Not Valid for headquarters,valid only for locations set up under a 	  particular main HeadQuarters of the Company
	$optionsettings=0;  
	$emailsettings=0; 
	
	$insert_sql="insert into business_info set businesscategory='$businesscategory' , companyname='$companyname' , locationname='$locationname' , parent='$parent' , firstname='$firstname' , lastname='$lastname' , email='$email' , address='$address' , city='$city' , state='$state' , zipcode='$zipcode' , country='$country' , timezone='$tinezone' , phonenumber='$phonenumber' , faxnumber='$faxnumber' , webaddress='$webaddress' , directions='$directions', optionsettings='$optionsettings' , emailsettings='$emailsettings'";
	mysql_query($insert_sql);
	
	
	$business_id = mysql_insert_id();
	
	###############   Inserting Information Of Administrator Of Business Into administrator_info_table #############
	
	$username=$TRLEN_UserName;
	$password=$TR_Password;
	$accesstype="admin";  //Thru Site Administration=>staff=>Add New Staff , staff and general user will be made
	$staffmembertype=''; //Not Valid For admin, valid only if accesstype=staff
	$status=$GL_active;
	$loginip=$REMOTE_ADDR;
	
	if($IN_Access_Days!="")
	{
	   $accessdays=$IN_Access_Days;
	}
	else
	{
       $accessdays=0;
	}
	$dateadded=date("Y-m-d H:i:s");
	$insert_admin_sql="insert into $administrator_info_table set business_id='$business_id' , username='$username' , password='$password' , accesstype='$accesstype' , staffmembertype='$staffmembertype' , status='$status' , loginip='$loginip'  , dateadded='$dateadded',package_id=1";
	mysql_query($insert_admin_sql);
	
	$administrator_id=mysql_insert_id();
	
	//For Sending Confirmation Mail To The Administrator Of the Account
	$subject="Free Trial Confirmation";
	
	$login_url=$site_url;

	$provider_url=$site_url;

	if($business_id!='') {
		$mail = new mailer($business_id);
		$mail->createBusiness();
	}

	// To send HTML mail, the Content-type header must be set
	// Send
	// mail($email,$subject, $message);
	
	header("location: gotologin.php?bid=$business_id&aid=$administrator_id&msg=Added");
	exit();
}
?>